//package de.au.fi.manager;
//
//import java.util.Arrays;
//import java.util.List;
//
//import javax.faces.application.FacesMessage;
//import javax.faces.context.FacesContext;
//
//import org.ektorp.CouchDbConnector;
//import org.ektorp.ViewQuery;
//import org.ektorp.support.CouchDbRepositorySupport;
//import org.ektorp.support.GenerateView;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import de.au.fi.domain.Stock;
//import de.au.fi.domain.EntityHelper;
//
//@Component
//@Service
//public class TestManager extends GenericManager<Stock> {
//
//	Logger log = LoggerFactory.getLogger(this.getClass());
//
//	@Autowired
//	public TestManager(@Qualifier("stockDatabase") CouchDbConnector db) {
//		super(db, Stock.class);
//		initStandardDesignDocument();
//	}
//}
//
//
//
//
//
//package de.au.fi.manager;
//
//import java.util.Arrays;
//import java.util.List;
//
//import javax.faces.application.FacesMessage;
//import javax.faces.context.FacesContext;
//
//import org.ektorp.CouchDbConnector;
//import org.ektorp.ViewQuery;
//import org.ektorp.support.CouchDbRepositorySupport;
//import org.ektorp.support.GenerateView;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import de.au.fi.domain.Stock;
//import de.au.fi.domain.EntityHelper;
//
//@Component
//@Service
//public class StockManager extends CouchDbRepositorySupport<Stock> {
//
//	Logger log = LoggerFactory.getLogger(this.getClass());
//
//	@Autowired
//	public StockManager(@Qualifier("stockDatabase") CouchDbConnector db) {
//		super(Stock.class, db);
//		initStandardDesignDocument();
//	}
//	
//	public List<Stock> saves(Stock... stocks) {
//		for(Stock stock : stocks)
//			save(stock);
//		return Arrays.asList(stocks);
//	}
//	
//	public List<Stock> saves(List<Stock> stocks) {
//		return saves(stocks.toArray(new Stock[stocks.size()]));
//	}
//
//	public Stock save(Stock stock) {
//		try {
//			if (stock.getId() == null) {
//				try {
//					FacesContext.getCurrentInstance().addMessage(null,
//							new FacesMessage("no id given cannot save"));
//				} catch (Exception e) {
//					log.error("Could not write faces msg, probably test.");
//				}
//				return stock;
//			}
//			if (contains(stock.getId())) {
//			Stock oldStock = get(stock.getId());
//			stock = EntityHelper.synchronizeObjects(stock, oldStock);
//			db.update(stock);
//			} else
//				db.create(stock);
//		} catch (Exception e) {
//			log.error("Error saving stock {}", stock.getId(), e);
//		}
//		return get(stock.getWkn());
//	}
//
//	@GenerateView @Override
//	public List<Stock> getAll() {
//		ViewQuery q = createQuery("all")
//						.descending(true)
//						.includeDocs(true);
//		return db.queryView(q, Stock.class);
//	}
//}


//package de.au.fi.manager;
//
//import java.util.Arrays;
//import java.util.List;
//
//import javax.faces.application.FacesMessage;
//import javax.faces.context.FacesContext;
//
//import org.ektorp.CouchDbConnector;
//import org.ektorp.ViewQuery;
//import org.ektorp.support.CouchDbRepositorySupport;
//import org.ektorp.support.GenerateView;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import de.au.fi.domain.Stock;
//import de.au.fi.domain.EntityHelper;
//import de.au.fi.domain.StockIdMapping;
//import de.au.fi.domain.StockIdMappingHelper;
//
//@Component
//@Service
//public class StockIdMappingManager extends
//		CouchDbRepositorySupport<StockIdMapping> {
//
//	Logger log = LoggerFactory.getLogger(this.getClass());
//
//	@Autowired
//	public StockIdMappingManager(@Qualifier("stockDatabase") CouchDbConnector db) {
//		super(StockIdMapping.class, db);
//		initStandardDesignDocument();
//	}
//
//	public List<StockIdMapping> saveIdMappings(
//			StockIdMapping... idMappings) {
//		for (StockIdMapping stockIdMapping : idMappings)
//			saveIdMapping(stockIdMapping);
//		return Arrays.asList(idMappings);
//	}
//
//	public List<StockIdMapping> saves(List<StockIdMapping> stockIdMappings) {
//		return saveIdMappings(stockIdMappings
//				.toArray(new StockIdMapping[stockIdMappings.size()]));
//	}
//
//	public StockIdMapping saveIdMapping(StockIdMapping stockIdMapping) {
//		try {
//			if (stockIdMapping.getId() == null) {
//				try {
//					FacesContext.getCurrentInstance().addMessage(null,
//							new FacesMessage("no id given cannot save"));
//				} catch (Exception e) {
//					log.error("Could not write faces msg, probably test.");
//				}
//				return stockIdMapping;
//			}
//			if (contains(stockIdMapping.getId())) {
//				StockIdMapping oldStockIdMapping = get(stockIdMapping.getTickerYahooData());
//				stockIdMapping = EntityHelper.synchronizeObjects(
//						stockIdMapping, oldStockIdMapping);
//				db.update(stockIdMapping);
//			} else
//				db.create(stockIdMapping);
//		} catch (Exception e) {
//			log.error("Error saving stock {}", stockIdMapping.getId(), e);
//		}
//		return get(stockIdMapping.getTickerYahooData());
//	}
//	
//	@GenerateView @Override
//	public List<StockIdMapping> getAll() {
//		ViewQuery q = createQuery("all")
//						.descending(true)
//						.includeDocs(true);
//		return db.queryView(q, StockIdMapping.class);
//	}
//}

